export default {
    data() {
        return {
            wsurl: undefined,
            rm: undefined
        }
    },
    methods: {
        /**
         * 关闭websocket时
         * */
        closeSocket: function () {
            let that = this;
            setTimeout(function () {
                that.socketInit(that.wsurl, that.rm);
            }, 2000);
            // this.socketInit();
        },

        /**
         * 初始化websocket
         * */
        socketInit: function (wsUrl, readMessage) {
            this.wsurl = wsUrl;
            this.rm = readMessage;
            this.ws = new WebSocket(wsUrl);
            this.ws.onmessage = readMessage;
            this.ws.onclose = this.closeSocket;
        },
        sendToClose: function () {
            this.ws.send("close it !!");
        }
    },
    beforeDestroy() {
        this.sendToClose()
    }
}